package com.itheima.producer_consumer;

public class Producer extends Thread {
    Desk desk;
    public Producer(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        //不停的生产
        while (true) {
            //加锁
            synchronized (desk.getLock()) {
                //生产10个停下
                if (desk.getCount() == 0) {
                    break;
                }
                //判断标记
                if (desk.isFlag()) {
                    //等待--锁对象调用方法
                    try {
                        desk.getLock().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    //生产
                    System.out.println("生产一个汉堡包");
                    //改变标记
                    boolean flag = desk.isFlag();
                    flag = true;
                    //唤醒等待线程
                    desk.getLock().notifyAll();
                }
            }
        }
    }
}
